#include <iostream>
#include "denoiser.h"
#include "audio_utils.h"

void print_usage(const char* program_name) {
    std::cerr << "Usage: " << program_name << " -i <input.wav> -o <output.wav> [-m <model_path>]\n";
    std::cerr << "Options:\n";
    std::cerr << "  -i <file>    Input WAV file\n";
    std::cerr << "  -o <file>    Output WAV file\n";
    std::cerr << "  -m <file>    Model file (optional)\n";
}

int main(int argc, char* argv[]) {
    std::string input_file;
    std::string output_file;
    std::string model_file = "../model_files/dns64-a7761ff99a7d5bb6_traced.pt";  // 默认模型路径
    
    // 解析命令行参数
    for (int i = 1; i < argc; i++) {
        std::string arg = argv[i];
        if (arg == "-i" && i + 1 < argc) {
            input_file = argv[++i];
        } else if (arg == "-o" && i + 1 < argc) {
            output_file = argv[++i];
        } else if (arg == "-m" && i + 1 < argc) {
            model_file = argv[++i];
        } else {
            print_usage(argv[0]);
            return 1;
        }
    }
    
    // 检查必要的参数
    if (input_file.empty() || output_file.empty()) {
        print_usage(argv[0]);
        return 1;
    }

    try {
        // 初始化降噪器
        std::cout << "Loading model from: " << model_file << "\n";
        Denoiser denoiser(model_file);
        
        // 处理音频文件
        std::cout << "Processing " << input_file << " -> " << output_file << "\n";
        denoiser.process_file(input_file, output_file);
        
        std::cout << "Done!\n";
    } catch (const std::exception& e) {
        std::cerr << "Error: " << e.what() << "\n";
        return 1;
    }

    return 0;
} 